package entity

import (
	"strconv"
	"time"

	"shqsoft.cn/pasnj/base"
	"shqsoft.cn/pasnj/bi/cube"
)

type CompCmFbblc struct {
	ID      int        `gorm:"AUTO_INCREMENT;primary_key;column:JLID"`
	SJRQ    *time.Time `gorm:"column:DATA_DT;type:date;"`
	KHMC    string     `gorm:"column:CUST_NAME"`
	Zjhm    string     `gorm:"column:ORG_ORG_CD;size:20"`
	Ssjg    string     `gorm:"column:LVL5_ORG_NAME;size:20"`
	Cpdm    string     `gorm:"column:CHREM_PROD_CD;size:20"`
	Qxr     *time.Time `gorm:"column:PROD_START_INT_DT;type:date;"`
	Dqr     *time.Time `gorm:"column:PROD_MATURE_DT;type:date;"`
	CYNM    string     `gorm:"column:CYNM;"`
	Qxzqs   *float64   `gorm:"column:TERM_PERIOD_CNT;"`
	Yfse    *float64   `gorm:"column:CURR_MONTH_AMT;"`
	CURRBAL *float64   `gorm:"column:CURR_BAL;"`
	Khsyl   *float64   `gorm:"column:CUST_ACTL_PRFT_RATE;"`
	Yaval   *float64   `gorm:"column:MONTH_DAYAVG_BAL;"`
	Cpmc    string     `gorm:"column:PROD_NAME;"`
	CUID    int        `gorm:"column:CUID"`
	YG1     string     `gorm:"-"`
	ZB1     *float64   `gorm:"-"`
	YG2     string     `gorm:"-"`
	ZB2     *float64   `gorm:"-"`
	YG3     string     `gorm:"-"`
	ZB3     *float64   `gorm:"-"`
	YG4     string     `gorm:"-"`
	ZB4     *float64   `gorm:"-"`
	YG5     string     `gorm:"-"`
	ZB5     *float64   `gorm:"-"`
}

//TableName 表名对公非保本理财
func (CompCmFbblc) TableName() string {
	return "V_COMP_CM_CUST_UNBREAK_EVEN_CHREM_INVEST_SUM_M"

}
func (c *CompCmFbblc) AfterFind() (err error) {
	var share *cube.Share
	share, err = cube.GetShare("comp_qtzb_divi")
	if err != nil {
		return
	}
	var diviMap map[string]float64
	diviMap, err = share.GetDivision("8:" + strconv.Itoa(c.ID))
	if err != nil {
		return
	}
	i := 0
	if diviMap == nil || len(diviMap) == 0 {
		share, err = cube.GetShare("comp_clie_divi")
		if err != nil {
			return
		}
		diviMap, err = share.GetDivision(strconv.Itoa(c.CUID))
		if err != nil {
			return
		}
	}
	for k, v := range diviMap {
		val := v
		i++
		switch i {
		case 1:
			c.YG1 = k
			c.ZB1 = &val
		case 2:
			c.YG2 = k
			c.ZB2 = &val
		case 3:
			c.YG3 = k
			c.ZB3 = &val
		case 4:
			c.YG4 = k
			c.ZB4 = &val
		case 5:
			c.YG5 = k
			c.ZB5 = &val
		default:
			break
		}
	}
	return
}

//CompCmFbblc 对公非保本理财
func CompCmFbblcEF() base.EntityFunc {
	return func() interface{} {
		entity := CompCmFbblc{}
		return &entity
	}
}

//CompCmFbblc 对公非保本理财
func CompCmFbblcESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []CompCmFbblc
		return &entities
	}
}
func init() {
	dao := base.NewDefaultDao(CompCmFbblcEF(), CompCmFbblcESF(), nil)
	filter := base.DefaultFilter{
		// FilterColName: "JLID",
		// TableName:     "T_COMP_QTZB_DIVI",
		// EmidColName:   "emid",
		// AcidColName:   "jlid",
		// WhereCause:    "ywid=7",
		FilterColName: "CUID",
		TableName:     "T_COMP_CLIE_YGFC",
		EmidColName:   "emid",
		AcidColName:   "CUID",
		WhereCause:    "DTID=dbo.GetDateToInt(dbo.GetCurSysDate())",
	}
	dao.Fileter = &filter
	base.DaoPoolObj.Put("CompCmFbblc", dao)
}
